<template>
  <div class="header">
    <div class="container">
      <div class="logo">
        <nuxt-link to="/">
          <img src="http://157.122.54.189:9093/images/logo.jpg" alt />
        </nuxt-link>
      </div>
      <div class="nav">
        <ul>
          <li v-for="(item,index) in navList" :key="index">
            <nuxt-link :to="item.url">{{item.name}}</nuxt-link>
          </li>
        </ul>
      </div>

      <!-- 登录 -->
      <div class="login" v-if="!$store.state.user.userInfo.token">
        <nuxt-link to="/user/login">
          登录
          <span>/</span> 注册
        </nuxt-link>
      </div>
      <!-- 个人 -->
      <div class="person" v-else>
        <el-dropdown>
          <span class="el-dropdown-link">
            <img :src="$axios.defaults.baseURL+$store.state.user.userInfo.user.defaultAvatar" alt />
            {{$store.state.user.userInfo.user.nickname}}
            <i
              class="el-icon-arrow-down el-icon--right"
            ></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      navList: [
        {
          name: '首页',
          url: '/'
        },
        {
          name: '旅游攻略',
          url: '/post'
        },
        {
          name: '酒店',
          url: '/hotel'
        },
        {
          name: '国内机票',
          url: '/air'
        }
      ],
      currenIndex: 0,
      loginFlag: false
    }
  },
  created() {
    console.log(this.$store.state.user.userInfo.user === null)
  },
  methods: {
    // 退出
    logout() {
      this.$message.success('退出成功')
      this.$store.commit('user/clearUserInfo')
    }
  }
}
</script>
<style lang="less" scoped>
.container {
  width: 1000px;
  min-width: 1000px;
  // background: pink;
  margin: 0 auto;
  display: flex;
  display: flex;
  align-items: center;
}
.header {
  display: flex;
  align-items: center;
  width: 100%;
  height: 60px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  .logo {
    width: 156px;
    height: 43px;

    img {
      width: 100%;
      height: 100%;
    }
  }
  .nav {
    .nuxt-link-exact-active {
      background: #409eff;
      color: #fff !important;
    }
    ul {
      list-style: none;
      li {
        float: left;
        line-height: 60px;
        height: 60px;
        &:hover {
          border-bottom: 5px solid #409eff;
          a {
            color: #409eff;
          }
        }
        a {
          width: 100%;
          height: 100%;
          padding: 0 20px;
          display: block;
          text-decoration: none;
          color: #000;
        }
      }
    }
  }
  .login {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    font-size: 14px;
    color: #666666;
    a {
      color: #666666;
      text-decoration: none;
      &:hover {
        color: #409eff;
        text-decoration: underline;
      }
    }
  }
  .person {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    img {
      width: 36px;
      height: 36px;
      border-radius: 50%;
    }
    .el-dropdown-link {
      display: flex;
      align-items: center;
    }
    .el-dropdown:hover {
      cursor: pointer;
      img {
        border: 2px solid #409eff;
      }
    }
  }
}
</style>